
import java.util.Random;
import javax.microedition.rms.RecordComparator;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author FFK
 */
public class readWriteFile {
    
    private RecordStore rs = null;
    private RecordStore rsMT = null;
    //static final String REC_STORE = "db_1"; // db cua score
    static final String REC_STORE_MT = "dulieu";// db cua ma tran
    public String sc;
    public int  [] ArrayMine;
    public readWriteFile() {
        ArrayMine = new int[81];
        for(int i = 0; i < 81 ; i ++){
            ArrayMine[i]= 0;
        }
        ArrayMine[75]=1;
        ArrayMine[52]=1;
        ArrayMine[6]=1;
        ArrayMine[70]=1;
        ArrayMine[60]=1;
        ArrayMine[7]=1;
        ArrayMine[45]=1;
        ArrayMine[35]=1;
        ArrayMine[2]=1;
        //doc_mang();
     
    }
    public void doc_mang() throws RecordStoreException
    {
      
    }
    /*
    public void read(boolean isHightScore){
        openRecStore(isHightScore);   // Create the record store
        if(isHightScore == true){
            try
            {
              if (rs.getNumRecords() > 0)
              {
                Comparator comp = new Comparator();

                RecordEnumeration re = rs.enumerateRecords(null, comp, false);
                int index =0;
                while (re.hasNextElement())
                {
                  String str = new String(re.nextRecord());
                   if(index == 0){
                      sc = str;
                      index++;
                      break;
                   }
                  // System.out.println(sc);
                  index++;

                }
              }
            }
            catch (Exception e)
            {
              db(e.toString());
            }
        }
        else{
            try
            {
              if (rsMT.getNumRecords() > 0)
              {
                int dong = 0, cot =0;
                Comparator comp = new Comparator();

                RecordEnumeration re = rsMT.enumerateRecords(null, comp, false);
                int index =0;
                while (re.hasNextElement())
                {
                    String str = new String(re.nextRecord());
                    ArrayMine[index] = Integer.parseInt(str);
                 
                  // System.out.println(ArrayMine[index]);
                   index++;
                }
              }
            }
            catch (Exception e)
            {
              db(e.toString());
            }
        }
        
        closeRecStore(isHightScore);  
    }
      */
    
/*
    public void openRecStore(boolean isHightScore)
    {
        try
        {
            if(isHightScore)
                rs = RecordStore.openRecordStore(REC_STORE, true );
            else
                rsMT = RecordStore.openRecordStore(REC_STORE_MT, true );
        }
        catch (Exception e)
        {
          db(e.toString());
        }
    }   
    */
    /*
     public void closeRecStore(boolean isHightScore)
      {
        try
        {
            if(isHightScore)
                rs.closeRecordStore();
            else
                rsMT.closeRecordStore();
        }
        catch (Exception e)
        {
          db(e.toString());
        }
      }
     
     */
    /*
      public final void deleteRecStore(boolean isHightScore)
      {
        if (RecordStore.listRecordStores() != null)
        {
          try
          {
              if(isHightScore)
                RecordStore.deleteRecordStore(REC_STORE);
              else
                  RecordStore.deleteRecordStore(REC_STORE_MT);
          }
          catch (Exception e)
          {
            db(e.toString());
          }
        }      
      }
      */
      public void viet(String str) throws RecordStoreException{
          rsMT = RecordStore.openRecordStore(REC_STORE_MT, true );
          byte[] rec = str.getBytes();
          System.out.print("luc viet");
          System.out.println(str);
          rsMT.addRecord(rec, 0, rec.length);
      }
      /*
      public void writeOneRecord(String str, boolean  isHightScore)
      {
        openRecStore(isHightScore); 
        byte[] rec = str.getBytes();
      //  System.out.println(str);
        try
        {
            if(isHightScore == true)
                rs.addRecord(rec, 0, rec.length);
            else
                rsMT.addRecord(rec, 0, rec.length);
        }
        catch (Exception e)
        {
          db(e.toString());
        }
        closeRecStore(isHightScore);
      }
      */
      private void db(String str)
      {
        System.err.println("Msg: " + str);
      }
    
}


//class Comparator implements RecordComparator
//{
//  public int compare(byte[] rec1, byte[] rec2)
//  {
//    String str1 = new String(rec1), str2 = new String(rec2);
//    
//    int result = str1.compareTo(str2);
//    if (result == 0)
//      return RecordComparator.EQUIVALENT;
//    else if (result < 0)
//      return RecordComparator.PRECEDES;
//    else
//      return RecordComparator.FOLLOWS;          
//  }
//}

